<!DOCTYPE html>
<title>SMIL 'values' whitespace</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg></svg>
<script>
let subjects = [
  { char: '\u0009', stripped: true,  name: 'Character Tabulation' },
  { char: '\u000A', stripped: true,  name: 'Line Feed' },
  { char: '\u000C', stripped: true,  name: 'Form Feed' },
  { char: '\u000D', stripped: true,  name: 'Carriage Return' },
  { char: '\u0020', stripped: true,  name: 'Space' },
  { char: '\u00A0', stripped: false, name: 'No-Break Space' },
  { char: '\u1680', stripped: false, name: 'Ogham Space Mark' },
  { char: '\u2000', stripped: false, name: 'EN Quad' },
  { char: '\u2001', stripped: false, name: 'EM Quad' },
  { char: '\u2002', stripped: false, name: 'EN Space' },
  { char: '\u2003', stripped: false, name: 'EM Space' },
  { char: '\u2004', stripped: false, name: 'Three-Per-Em Space' },
  { char: '\u2005', stripped: false, name: 'Four-Per-Em Space' },
  { char: '\u2006', stripped: false, name: 'Six-Per-Em Space' },
  { char: '\u2007', stripped: false, name: 'Figure Space' },
  { char: '\u2008', stripped: false, name: 'Punctuation Space' },
  { char: '\u2009', stripped: false, name: 'Thin Space' },
  { char: '\u200A', stripped: false, name: 'Hair Space' },
  { char: '\u202F', stripped: false, name: 'Narrow No-Break Space' },
  { char: '\u205F', stripped: false, name: 'Medium Mathematical Space' },
  { char: '\u3000', stripped: false, name: 'Ideographic Space' },
];

function makeTestSubject(subjectText) {
  const svgNs = 'http://www.w3.org/2000/svg';
  let aLink = document.createElementNS(svgNs, 'a');
  let rect = aLink.appendChild(document.createElementNS(svgNs, 'rect'));
  rect.setAttribute('width', 100);
  rect.setAttribute('height', 100);
  rect.setAttribute('fill', 'blue');
  let animate = aLink.appendChild(document.createElementNS(svgNs, 'animate'));
  animate.setAttribute('attributeName', 'href');
  animate.setAttribute('values', subjectText);
  return aLink;
}

let svgRoot = document.querySelector('svg');
for (let subject of subjects) {
  async_test(function(t) {
    let payload = 'javascript:alert("' + subject.name + '")';
    let fragment = makeTestSubject(subject.char + payload);
    svgRoot.appendChild(fragment);
    let expected = (subject.stripped ? '' : subject.char) + payload;
    let animate = fragment.lastChild;
    animate.onbegin = t.step_func_done(function() {
      var target = animate.parentNode;
      assert_equals(target.href.animVal, expected);
    });
  }, subject.name + ' (U+' +  subject.char.codePointAt(0).toString(16) +  ') is ' +
     (subject.stripped ? '' : 'not ') + 'stripped.');
};
</script>
